package io.gitee.zicai.bus.listener;

import io.gitee.zicai.bus.adaptor.IBusReceiveAdaptor;
import io.gitee.zicai.bus.bus.IReceiveBus;
import io.gitee.zicai.bus.core.IBusReceiver;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * BaseBusReceiveListener
 *
 * @author zicai
 * @since 2021-01-20
 */
@Slf4j
public abstract class BaseBusReceiveListener<R extends IBusReceiver, RB extends IReceiveBus<R, RT>, RT> implements IBusReceiveListener<R, RB, RT> {

    public void cmdReceiveHandler(IBusReceiveAdaptor<R, RB, RT> cmdReceiveAdaptor, RB bus) {
        if (Objects.isNull(bus.getBiConsumer())) {
            log.warn(">>> There is no ReceiveMethod for payload -> {}", bus.getReceiveData());
            return;
        }
        cmdReceiveAdaptor.invokeCmd().accept(bus);
    }
}
